const conf = require("../conf/web")
const {FORBIDDEN} = require("../enumeration/code")
const {getUserInfo, result} = require("../utils")
module.exports = async (ctx) => {
  let token = ctx.req.headers[conf.auth.key]
  if (token) {
    let res = await getUserInfo(token)
    if (res) {
      return true
    } else {
      return Promise.reject(result(0, "权限校验失败", FORBIDDEN))
    }
  } else {
    return Promise.reject(result(0, "权限校验失败", FORBIDDEN))
  }
}
